using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VFSSTAMM
    {
   
        public DataSet QueryFSSTAMM(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1 = null;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM FSSTAMM WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM FSSTAMM  "
                    + " WHERE FSMANDANT=:FSMANDANT AND FSART=:FSART AND FSVAR=:FSVAR";
                    or1.Parameters.Add("FSMANDANT", OracleType.NVarChar).Value = dwData["FSMANDANT"].ToString();
                    or1.Parameters.Add("FSART", OracleType.NVarChar).Value = dwData["FSART"].ToString();
                    or1.Parameters.Add("FSVAR", OracleType.NVarChar).Value = dwData["FSVAR"].ToString();
                    //FFSMANDANT	FSART	FSVAR 
                    break;
                case 2:
                    or1 = OracleDB.CreateCommand();
                    or1.CommandText = "SELECT * FROM FSSTAMM  "
                    + " WHERE FSMANDANT=:FSMANDANT AND FSART=:FSART";
                    or1.Parameters.Add("FSMANDANT", OracleType.NVarChar).Value = dwData["FSMANDANT"].ToString();
                    or1.Parameters.Add("FSART", OracleType.NVarChar).Value = dwData["FSART"].ToString();
                    break;
                case 3:
                    or1 = OracleDB.CreateCommand();
                    or1.CommandText = "SELECT FSART,FSABEZ FROM FSSTAMM  "
                    + " WHERE FSMANDANT=:FSMANDANT AND FSART LIKE '2%' ";
                    or1.Parameters.Add("FSMANDANT", OracleType.NVarChar).Value = dwData["FSMANDANT"].ToString();
                    break;
                case 4:
                    or1 = OracleDB.CreateCommand();
                    string FSART = dwData["FSART"].ToString().Trim();
                    or1.CommandText = "SELECT FSMANDANT,FSART,FSVAR,FSABEZ FROM FSSTAMM  "
                    + " WHERE FSMANDANT=:FSMANDANT AND FSART LIKE '" + FSART + "%' ORDER BY 1,2,3";
                    or1.Parameters.Add("FSMANDANT", OracleType.NVarChar).Value = dwData["FSMANDANT"].ToString();
                    //or1.Parameters.Add("FSART", OracleType.NVarChar).Value = dwData["FSART"].ToString();
                    break;
                case 5:
                    or1 = OracleDB.CreateCommand();
                    or1.CommandText = "SELECT DISTINCT FSMANDANT,FSART,FSVAR,FSABEZ FROM FSSTUELI S JOIN FSSTAMM M ON FSSART=M.FSART"
                        + " WHERE FSSMANDANT=:FSSMANDANT AND  S.FSSMART=:FSSMART ORDER BY 1,2,3";
                    or1.Parameters.Add("FSSMANDANT", OracleType.NVarChar).Value = dwData["FSSMANDANT"].ToString();
                    or1.Parameters.Add("FSSMART", OracleType.NVarChar).Value = dwData["FSSMART"].ToString();
                    break;
                case 6:
                    or1 = OracleDB.CreateCommand();
                    string s = dwData["FSSART"].ToString().Trim();
                    or1.CommandText = "SELECT DISTINCT FSMANDANT,FSART,FSVAR,FSABEZ FROM FSSTAMM JOIN FSSTUELI ON FSSART=FSART "
                    + " WHERE FSMANDANT=:FSMANDANT AND FSSART LIKE '" + s + "%'  AND FSSMART=:FSSMART ORDER BY 1,2,3";
                    or1.Parameters.Add("FSMANDANT", OracleType.NVarChar).Value = dwData["FSSMANDANT"].ToString();
                    or1.Parameters.Add("FSSMART", OracleType.NVarChar).Value = dwData["FSSMART"].ToString();
                    //or1.Parameters.Add("FSART", OracleType.NVarChar).Value = dwData["FSART"].ToString();
                    break;
                case 7:
                    or1.CommandText = "SELECT MAX(FSKOLL) AS FSKOLL FROM FSSTAMM  "
                    + " WHERE FSMANDANT=:FSMANDANT";
                    or1.Parameters.Add("FSMANDANT", OracleType.NVarChar).Value = dwData["FSMANDANT"].ToString();
                    //FFSMANDANT	FSART	FSVAR 
                    break;
                case 8:
                    or1.CommandText = "SELECT DISTINCT F.* FROM FSSTAMM F  RIGHT JOIN ABPOS ON ABPMANDANT=FSMANDANT AND FSART=ABPART"
                    + " WHERE ABPMANDANT=:ABPMANDANT AND ABPART=:ABPART AND ABPVAR=:ABPVAR";
                    or1.Parameters.Add("ABPMANDANT", OracleType.NVarChar).Value = dwData["ABPMANDANT"].ToString();
                    or1.Parameters.Add("ABPART", OracleType.NVarChar).Value = dwData["ABPART"].ToString();
                    or1.Parameters.Add("ABPVAR", OracleType.NVarChar).Value = dwData["ABPVAR"].ToString();
                    //FFSMANDANT	FSART	FSVAR 
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);

            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "FSSTAMM";
            }
            setReturn.Merge(Result);
            return setReturn;
        }
    }
}
